//var mUrl = 'http://39.106.114.52:8080/hunt-admin';
//var mUrl = 'http://47.93.1.92:8999/hunt-admin';
var mUrl = 'http://39.105.51.148:7878/hunt-admin';//正式服务器
//var mUrl = 'http://192.168.1.152:8080/hunt-admin';//测试服务器
//var mUrl = 'http://localhost:7878';//本机服务器
user_tool_level = {
    form_clear: function () {
        // $("#userLevel_form").form('reset');
        // $("#userLevel_form").form('clear');
        // $("#user-userLevel-search-form-form").form('reset');
        // $("#user-userLevel-search-form-form").form('clear');
        // $("#userLevel_grid").treegrid("uncheckAll");
    },




    init_level_edit_view: function () {
        $("#userLevel_edit_dialog").dialog({
            title: '修改用户级别',
            iconCls: 'icon-edit',
            closable: true,
            cache: false,
            modal: true,
            resizable: false,
            width: 500,
            height: 500,
            'onBeforeOpen': function () {
                $('#userlevel0').textbox({

                    editable:false
                })
                // $('#etime').textbox({
                //
                //     editable:false
                // })

            },
            'onOpen': function () {
            },
            'onClose': function () {
                user_tool_level.form_clear();
            },
            buttons: [
                {
                    text: '修改',
                    width: 100,
                    iconCls: 'icon-save',
                    handler: function () {
                        common_tool.messager_show("icon-save");
                        user_tool_level.updateUserLevel();

                    }
                },

                {
                    text: '取消',
                    width: 100,
                    iconCls: 'icon-add',
                    handler: function () {
                        user_tool_level.form_clear();
                        $("#userLevel_edit_dialog").dialog('close');
                    }
                }
            ]
        })




    },
    form_clear: function () {
        // $("#userLevel_form").form('reset');
        // $("#userLevel_form").form('clear');
        // $("#userLevel_grid").treegrid("uncheckAll");
    },
    init_main_view: function () {

        $("#userLevel_grid").datagrid({
            // url: getRootPath()+'/userlevel/listByPage',
            url: getRootPath() + '/userlevel/listByPage0',
            method: 'get',
            idField: "id",
            fitColumns: true,
            toolbar: '#userlevel-tool-bar',
            rownumbers: true,
            animate: true,
            singleSelect: true,
            fit: true,
            border: false,
            pagination: true,
            striped: true,
            pagePosition: "bottom",
            pageNumber: 1,
            pageSize: 15,
            pageList: [15, 30, 45, 60],
            queryParams: {
                pageNo: 1,
                pageSize: 15,
                order: 'asc'
            },
            columns: [[
                {title: "选择", field: "ck", checkbox: true},
                {
                    title: "用户级别",
                    field: "userlevel0",
                    width: 40,
                    sortable: true,
                    formatter: function (value, row, index) {
                        if (value == '0') {
                            return "体验用户";
                        }
                        if (value == '1') {
                            return "租用用户";
                        }
                        if (value == '2') {
                            return "经典用户";
                        }
                        if (value == '3') {
                            return "尊享用户";
                        }
                        if (value == '4') {
                            return "标准用户";
                        }
                        if (value == '5') {
                            return "待定用户1";
                        }
                        if (value == '6') {
                            return "待定用户2";
                        }
                    }
                },
                {
                    title: "有效期", field: "etime", width: 30, sortable: true, formatter: function (value, row, index) {
                        return value;
                    }
                },
                {
                    title: "晨光短线", width: 35, field: "cgdx", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "晨光中线", width: 35, field: "cgzx", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "晨光能量", width: 35, field: "cgln", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "晨光牛熊", width: 35, field: "cgnx", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },

                {
                    title: "多空趋势", width: 35, field: "dkqs", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "动能转换", width: 35, field: "dnzh", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "牛熊强弱", width: 35, field: "nxqr", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "中线趋势", width: 35, field: "zxqs", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "智能量", width: 35, field: "znl", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "大单动向", width: 35, field: "dddx", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "条件设置", width: 35, field: "yjxg", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "五维尊享", width: 35, field: "wwzx", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "条件统计", width: 35, field: "tjyj", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "大单统计", width: 35, field: "ddtj", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "北向资金", width: 35, field: "bxzj", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "7*24快讯", width: 35, field: "qeskx", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "资讯", width: 35, field: "zx", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "基金增仓", width: 35, field: "jjzc", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "五维训练", width: 35, field: "wwxl", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "热点掘金", width: 35, field: "rdjj", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "强势密码", width: 35, field: "ztmm", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "形态统计", width: 35, field: "ygls", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "神奇九转", width: 35, field: "sqjz", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "龙虎榜", width: 35, field: "lhb", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "北向追击", width: 35, field: "bxzhj", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "股票评级", width: 35, field: "gppj", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                },
                {
                    title: "热门游资", width: 35, field: "rmyz", formatter: function (value, row, index) {
                        if (value == 1) {
                            return "启用";
                        }
                        if (value == 0) {
                            return "关闭";
                        }
                    }
                }

            ]]

        });
    },

    // update: function (data) {
    updateUserLevel: function () {
        common_tool.messager_show("update");
        var form_isValid = $("#userLevel_form").form('validate');

        if (!form_isValid) {
            common_tool.messager_show("请输入必填参数")
        }
        else {
            var userlevel0 = $('#userLevel_edit_dialog input[name="userlevel0"]').val();
            var cgdx = $('#userLevel_edit_dialog input[name="cgdx"]').val();
            var cgzx = $('#userLevel_edit_dialog input[name="cgzx"]').val();
            var cgln = $('#userLevel_edit_dialog input[name="cgln"]').val();
            var cgnx = $('#userLevel_edit_dialog input[name="cgnx"]').val();
            var etime = $('#userLevel_edit_dialog input[name="etime"]').val();
            var dkqs = $('#userLevel_edit_dialog input[name="dkqs"]').val();
            var dnzh = $('#userLevel_edit_dialog input[name="dnzh"]').val();
            var nxqr = $('#userLevel_edit_dialog input[name="nxqr"]').val();
            var zxqs = $('#userLevel_edit_dialog input[name="zxqs"]').val();
            var znl = $('#userLevel_edit_dialog input[name="znl"]').val();
            var dddx = $('#userLevel_edit_dialog input[name="dddx"]').val();
            var yjxg = $('#userLevel_edit_dialog input[name="yjxg"]').val();
            var wwzx = $('#userLevel_edit_dialog input[name="wwzx"]').val();
            var tjyj = $('#userLevel_edit_dialog input[name="tjyj"]').val();
            var ddtj = $('#userLevel_edit_dialog input[name="ddtj"]').val();
            var bxzj = $('#userLevel_edit_dialog input[name="bxzj"]').val();
            var qeskx = $('#userLevel_edit_dialog input[name="qeskx"]').val();
            var zx = $('#userLevel_edit_dialog input[name="zx"]').val();
            var jjzc = $('#userLevel_edit_dialog input[name="jjzc"]').val();
            var wwxl = $('#userLevel_edit_dialog input[name="wwxl"]').val();
            var rdjj = $('#userLevel_edit_dialog input[name="rdjj"]').val();
            var ztmm = $('#userLevel_edit_dialog input[name="ztmm"]').val();
            var ygls = $('#userLevel_edit_dialog input[name="ygls"]').val();
            var sqjz = $('#userLevel_edit_dialog input[name="sqjz"]').val();
            var lhb = $('#userLevel_edit_dialog input[name="lhb"]').val();
            var bxzhj = $('#userLevel_edit_dialog input[name="bxzhj"]').val();
            var gppj = $('#userLevel_edit_dialog input[name="gppj"]').val();
            var rmyz = $('#userLevel_edit_dialog input[name="rmyz"]').val();
            //根据userlevel加载修改的信息
            var params = {};


            params.userlevel = userlevel0;
            params.cgdx = cgdx;
            params.cgzx = cgzx;
            params.cgln = cgln;
            params.cgnx = cgnx;
            params.etime = etime;
            params.dkqs = dkqs;
            params.dnzh = dnzh;
            params.nxqr = nxqr;
            params.zxqs = zxqs;
            params.znl = znl;
            params.dddx = dddx;
            params.yjxg = yjxg;
            params.wwzx = wwzx;
            params.tjyj = tjyj;
            params.ddtj = ddtj;
            params.bxzj = bxzj;
            params.qeskx = qeskx;
            params.zx = zx;
            params.jjzc = jjzc;
            params.wwxl = wwxl;
            params.rdjj = rdjj;
            params.ztmm = ztmm;
            params.ygls = ygls;
            params.sqjz = sqjz;
            params.lhb = lhb;
            params.bxzhj =bxzhj;
            params.gppj =gppj;
            params.rmyz =rmyz;

            $.ajax({
                data: params,
                traditional: true,
                method: 'post',
                url: getRootPath()+'/userlevel/update',
                async: false,
                dataType: 'json',
                success: function (result) {
                    // if (result.code == 1) {
                    if (result.code == 10000) {
                        $("#userLevel_edit_dialog").dialog("close");
                        user_tool_level.form_clear();
                        user_tool_level.init_main_view();
                        common_tool.messager_show(result.msg);
                        return false;
                    }
                    else {
                        common_tool.messager_show(result.msg);
                    }
                }
            });

        }
    }


};
$(document).ready(function () {
    user_tool_level.init_main_view();
    $("#userlevel-update-btn").click(function () {

        var user_levels = $("#userLevel_grid").datagrid('getSelected');
        //获得选中行
        if (!user_levels || user_levels.length == 0) {
            common_tool.messager_show("请您至少选择一条记录!!");
            return false;
        }

        var mul = user_levels.userlevel0;
        var cgdx = user_levels.cgdx;
        var cgzx = user_levels.cgzx;
        var cgln = user_levels.cgln;
        var cgnx = user_levels.cgnx;
        var etime = user_levels.etime;
        var dkqs = user_levels.dkqs;
        var dnzh = user_levels.dnzh;
        var nxqr = user_levels.nxqr;
        var zxqs = user_levels.zxqs;
        var znl = user_levels.znl;
        var dddx = user_levels.dddx;
        var yjxg = user_levels.yjxg;
        var wwzx = user_levels.wwzx;
        var tjyj = user_levels.tjyj;
        var ddtj = user_levels.ddtj;
        var bxzj = user_levels.bxzj;
        var qeskx = user_levels.qeskx;
        var zx = user_levels.zx;
        var jjzc = user_levels.jjzc;
        var wwxl = user_levels.wwxl;
        var rdjj = user_levels.rdjj;
        var ztmm = user_levels.ztmm;
        var ygls = user_levels.ygls;
        var sqjz = user_levels.sqjz;
        var lhb = user_levels.lhb;
        var bxzhj = user_levels.bxzhj;
        var gppj=user_levels.gppj;
        var rmyz=user_levels.rmyz;
        var mLevelStr;
        if(mul == "0"){
            mLevelStr = "体验账户"
        }
        if(mul == "1"){
            mLevelStr = "租用账户"
        }
        if(mul == "2"){
            mLevelStr = "经典账户"
        }
        if(mul == "3"){
            mLevelStr = "尊享账户"
        }
        if(mul == "4"){
            mLevelStr = "标准账户"
        }
        if(mul == "5"){
            mLevelStr = "待定账户1"
        }
        if(mul == "6"){
            mLevelStr = "待定账户2"
        }
        $("#userLevel_form").form('load', {
            userlevel0: mLevelStr,
            cgdx: cgdx,
            cgzx: cgzx,
            cgln: cgln,
            cgnx: cgnx,
            etime: etime,
            dkqs: dkqs,
            dnzh: dnzh,
            nxqr: nxqr,
            zxqs: zxqs,
            znl: znl,
            dddx: dddx,
            yjxg: yjxg,
            wwzx: wwzx,
            tjyj: tjyj,
            ddtj: ddtj,
            bxzj: bxzj,
            qeskx: qeskx,
            zx: zx,
            jjzc: jjzc,
            wwxl: wwxl,
            rdjj: rdjj,
            ztmm: ztmm,
            ygls: ygls,
            sqjz: sqjz,
            lhb: lhb,
            bxzhj:bxzhj,
           gppj:gppj,
           rmyz:rmyz
            });

        user_tool_level.init_level_edit_view();

    });
    // $("#userlevel-delete-btn").click(function () {
    //     var user_levels = $("#userLevel_grid").datagrid('getChecked');
    //     if (user_levels.length == 0) {
    //         common_tool.messager_show("请至少选择一条记录");
    //         return false;
    //     }
    //     $.messager.confirm('确认对话框', "您确认删除该条记录吗?", function (r) {
    //         if (r) {
    //             user_tool_level.delete(user_levels[0].userlevel);
    //         }
    //     });
    // });

    $("#userlevel-flash-btn").click(function () {
        user_tool_level.form_clear();
        user_tool_level.init_main_view();

    });
});